package com.sky.controller.admin;


import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单管理接口")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*
    * 订单分页查询
    * */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单分页")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单分页查询:{}",ordersPageQueryDTO);
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }
    @PutMapping("/confirm")
    @ApiOperation("接收订单")
    public Result confirm(@RequestBody OrdersDTO ordersDTO){
        log.info("接收订单:{}",ordersDTO);
        orderService.confirm(ordersDTO);
        return Result.success();
    }
    @PutMapping("rejection")
    @ApiOperation("拒收订单")
    public Result rejection(@RequestBody OrdersDTO ordersDTO) {
        log.info("拒收订单:{}",ordersDTO);
        orderService.rejection(ordersDTO);
        return Result.success();
    }
    @PutMapping("cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersDTO ordersDTO) {
        log.info("取消订单:{}",ordersDTO);
        orderService.cancel(ordersDTO);
        return Result.success();
    }
    @GetMapping("statistics")
    @ApiOperation("统计订单")
    public Result<OrderStatisticsVO> statistics(){
        log.info("统计订单:{}");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
    @PutMapping("delivery/{id}")
    @ApiOperation("派送订单")
    public Result delivery(@PathVariable Long id){
        log.info("派送订单:{}",id);
        orderService.delivery(id);
        return Result.success();
    }
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        log.info("完成订单:{}",id);
        orderService.complete(id);
        return Result.success();
    }
    @GetMapping("details/{id}")
    @ApiOperation("订单详情")
    public Result<OrderVO> detail(@PathVariable Long id){
        log.info("查看订单详情:{}",id);
        OrderVO orderVO = orderService.detail(id);
        return Result.success(orderVO);
    }
}